package com.example.booksales.controller;

import com.example.booksales.domain.Order;
import com.example.booksales.service.impl.OrderService;
import com.example.booksales.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
@Api(tags="订单管理(0613胡宇星)")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("获得全部订单列表(22001010613胡宇星)")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(orderService.getAllOrders());
    }

    @ApiOperation(value = "获取订单详细信息(22001010613胡宇星)", notes = "TODO：取得某个订单的详细信息")
    @ApiImplicitParam(name = "orderid", value = "订单ID",
            required = true, dataType = "long", paramType = "path",
            dataTypeClass = Long.class)
    @GetMapping(value = "/{orderid}")
    public AjaxResult getInfo(@PathVariable("orderid") Long orderid) {
        return AjaxResult.success(orderService.selectOrderById(orderid));
    }
    @ApiOperation("新增订单(22001010613胡宇星)")
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        return AjaxResult.success(orderService.insertOrder(order));
    }
    @ApiOperation("修改订单(22001010613胡宇星)")
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return AjaxResult.success(orderService.updateOrder(order));
    }
    @ApiOperation("删除订单(22001010613胡宇星)")
    @ApiImplicitParam(name = "orderid", value = "订单ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{orderid}")
    public AjaxResult remove(@PathVariable Long orderid) {
        return AjaxResult.success(orderService.deleteOrderById(orderid));
    }
}
